import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/afterSales/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询详情'
});
const modifyDesc = formatMessage({
    id: 'api.message.modifyDesc',
    defaultMessage: '修改售后车辆信息'
});
const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/vehicleSold/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/vehicleSolds/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
//修改售后车辆信息
export const modifyOrder = (id, data) => request(`${baseUrl}/vehicleSolds/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, modifyDesc));
// 导出
export const exports = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds/export/forCurrentUser?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
//导入模板
export const importTemp = () => request(`${baseUrl}/vehicleSolds/importTemp`)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, null)).then(res => res.data);

import {productCategoryType} from '../Enum';

const productCategoryQueryDesc = formatMessage({
    id: 'api.message.productCategoryQueryDesc',
    defaultMessage: '查询车型信息'
});
export const productCategoryQuery = () =>
    request(`${baseUrl}/productCategories?type=${productCategoryType.车型}&isAll=true`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, productCategoryQueryDesc));

// 导出
export const exportKds = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds/exportKd?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
